package kr.saeildadim.androidexam_saeildamil.chapter13;


import kr.saeildadim.androidexam_saeildamil.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListPopupWindow;

public class Ch13_ListPopup extends Activity {
	Button mbtn;
	ListPopupWindow mList;
	public String[] Colors= {"Red", "Green", "Blue", "yellow", "Cyan", "magenta"};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch13_listpopup);
		
		mbtn = (Button) findViewById(R.id.ch13_listpopup_btn);
		mList  = new ListPopupWindow(this);
		mList.setWidth(300);
		mList.setHeight(300);
		mList.setAnchorView(mbtn);
		mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Colors));
		mList.setModal(true);
		
		mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				switch(position){
				case 0:mbtn.setBackgroundColor(Color.RED);break;
				case 1:mbtn.setBackgroundColor(Color.GREEN);break;
				case 2:mbtn.setBackgroundColor(Color.BLUE);break;
				case 3:mbtn.setBackgroundColor(Color.YELLOW);break;
				case 4:mbtn.setBackgroundColor(Color.CYAN);break;
				case 5:mbtn.setBackgroundColor(Color.MAGENTA);break;
				
				
				} 
				
			}
		});
		
	}
	public void mOnClick(View v){
		if(mList.isShowing()){
			mList.dismiss();
		}else{
			mList.show();
		}
	}
}
